/* 
 * Enterprise Library Extensions - DI + ORM.
 * Copyright (C) 2006
 *
 * GNU General Public License
 *
 * This program is free software; you can redistribute 
 * it and/or modify it under the terms of the GNU General Public License 
 * as published by the Free Software Foundation; either version 2 of the 
 * License, or (at your option) any later version.
 * 
 * This program is distributed in the hope that it will be useful, but 
 * WITHOUT ANY WARRANTY; without even the implied warranty of 
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 
 * See the GNU General Public License for more details.
 */
using System;
using System.Collections;

namespace ELE.EnterpriseLibrary.Aspects.Sinks
{
	/// <summary>
	/// Summary description for AspectConfigurationList.
	///
	/// Author: Miguel Curi
  /// </summary>
  [Serializable]
  public class AspectConfigurationList : CollectionBase
  {
    /// <summary>
    /// Utility method to copy IAspectConfiguration elements only from an IList into this object
    /// </summary>
    /// <param name="source"></param>
    public static AspectConfigurationList CloneFromIList(IList source)
    {
      if(source == null) 
      {
        return null;
      }
      AspectConfigurationList list = new AspectConfigurationList();
      foreach(object o in source)
      {
        if(o is AspectConfiguration)
        {
          list.Add((AspectConfiguration)o);
        }
      }
      return list;
    }
    /// <summary>
    /// Type safe accessor of item in the list
    /// </summary>
    public AspectConfiguration this[ int index ]  
    {
      get  
      {
        return( (AspectConfiguration) List[index] );
      }
      set  
      {
        List[index] = value;
      }
    }
    /// <summary>
    /// Implementation of the type safe add
    /// </summary>
    /// <param name="value"></param>
    /// <returns></returns>
    public int Add( AspectConfiguration value )  
    {
      return( List.Add( value ) );
    }
    /// <summary>
    /// Implementation of IndexOf
    /// </summary>
    /// <param name="value"></param>
    /// <returns></returns>
    public int IndexOf( AspectConfiguration value )  
    {
      return( List.IndexOf( value ) );
    }
    /// <summary>
    /// Inserts an AspectConfiguration
    /// </summary>
    /// <param name="index">Index</param>
    /// <param name="value">AspectConfiguration</param>
    public void Insert( int index, AspectConfiguration value )  
    {
      List.Insert( index, value );
    }
    /// <summary>
    /// Contains the AspectConfiguration
    /// </summary>
    /// <param name="value">AspectConfiguration</param>
    /// <returns>True if successful</returns>
    public bool Contains( AspectConfiguration value )  
    {
      // If value is not of type Int16, this will return false.
      return( List.Contains( value ) );
    }
    /// <summary>
    /// Inserts an AspectConfiguration 
    /// </summary>
    /// <param name="index">Index</param>
    /// <param name="value">Object</param>
    protected override void OnInsert( int index, Object value )  
    {
      if(!(value is AspectConfiguration))
      {
        throw new ArgumentException( "value must be of type AspectConfiguration", "value" );
      }
    }
    /// <summary>
    /// Removes an AspectConfiguration
    /// </summary>
    /// <param name="index">Index</param>
    /// <param name="value">Object</param>
    protected override void OnRemove( int index, Object value )  
    {
      if(!(value is AspectConfiguration))
      {
        throw new ArgumentException( "value must be of type AspectConfiguration", "value" );
      }
    }
    /// <summary>
    /// Sets an AspectConfiguration
    /// </summary>
    /// <param name="index">Index</param>
    /// <param name="oldValue">oldValue</param>
    /// <param name="newValue">newValue</param>
    protected override void OnSet( int index, Object oldValue, Object newValue )  
    {
      if(!(newValue is AspectConfiguration))
      {
        throw new ArgumentException( "value must be of type AspectConfiguration", "value" );
      }
    }
    /// <summary>
    /// Validates an object.
    /// </summary>
    /// <param name="value">Object</param>
    protected override void OnValidate( Object value )  
    {
      if ( !(value is AspectConfiguration) )
        throw new ArgumentException( "value must be of type AspectConfiguration.", "value" );
    }

  }
}

